cd "C:\Users\49669\Desktop\小论文\计量数据\数据"
use have,clear
gen case2=1
replace case2=2 if case>5&case<11   
replace case2=3 if case>10&case<21 
replace case2=4 if case>20
describe
gen lprice=ln(price)
gen lhousehold=ln(household)
gen	lhospital=ln(hospital)
gen	lsubway=ln(subway)
gen	lshopping=ln(shopping)
sum case2 landlord lprice age plot lhousehold elevator floor market lhospital lsubway lshopping
tab case2 
histogram case2
reg case2 landlord price age plot household elevator floor market hospital subway shopping, robust
estat vif

mlogit case2 landlord lprice age plot lhousehold elevator floor lhospital lsubway lshopping, robust
outreg2 using 3.doc,replace ctitle(mlogit)
mcross //所有系数估计值对应的胜算比
mlogit, rrr
fitstat //拟合优度汇总
test landlord price plot household elevator market hospital shopping // wald检验，是否联合显著
qui mlogit case2 landlord price age plot household elevator floor market hospital subway shopping, robust
mlogtest, combine // 检验任意两组是否能合并
qui mlogit case2 landlord price age plot household elevator floor market hospital subway shopping,base(2) 
est store full
qui mlogit case2 landlord price age plot household elevator floor market hospital subway shopping if case2!=0
est store rist
hausman rist full, alleq constant //以0为基准组，其他组的独立性检验 
qui mlogit case2 landlord lprice age plot lhousehold elevator floor market lhospital lsubway lshopping, robust
predict y0 y1 y2 y3 //生成各类别预测值
des y*
sum y*
count if y0==1
dis "y0正确预测百分比= " r(N)/107 // 正确预测百分比
count if y1==1
dis "y1正确预测百分比= " r(N)/79 // 正确预测百分比
count if y2==1 
dis "y2正确预测百分比= " r(N)/84 // 正确预测百分比
count if y3==1
dis "y3正确预测百分比= " r(N)/62 // 正确预测百分比

qui mlogit case2 landlord price age plot household elevator floor market hospital subway shopping, robust
predict z3 // 生成总预测值
replace z3=1 if z3>0.25
count if z3==1
dis "正确预测百分比= " r(N)/_N // 正确预测百分比
predict u3, residual
histogram u3 // 残差直方图
qui mlogit case2 landlord lprice age plot lhousehold elevator floor market lhospital lsubway lshopping, robust
margins, at(landlord = (0.3(0.972) 5.16)) predict(outcome(0)) vsquish //不同取值时的平均预测概率
margins, at(landlord = (0.3(0.972) 5.16)) predict(outcome(1)) vsquish
margins, at(landlord = (0.3(0.972) 5.16)) predict(outcome(2)) vsquish
margins, at(landlord = (0.3(0.972) 5.16)) predict(outcome(3)) vsquish


poisson case landlord lprice age plot lhousehold elevator floor market lhospital lsubway lshopping,robust
outreg2 using i.doc,replace ctitle(poisson2)
